/*********************************************************
	Project:		ST FST(TDA7540)
	File name:	RDSData.h
	Description:	
	Write/Modify:	Perry Liang
	Time:		2006-1-24- 15:36:04
*********************************************************/
#ifdef SUPPORT_RDS	
extern void RDSInt(void);
extern void RDSDataInit(void);
extern void RDSDataMain(void);
extern void RDSExtrData(void);
extern void RDSAF(void);
extern void BreakAFCheck(void);
extern void BreakAFSearch(void);
extern void SetAFSearch(void);
extern void RDSAFDisable100ms(unsigned char timer);
extern void RDSDataTimer1s(void);
extern void RDSDataTimer100ms(void);
extern void RDSDataTimer10ms(void);
extern void RDSClearTAFlags(void);
extern void RDSClearEONTAFlags(void);
extern unsigned char ChangFreq16BitTo8Bit(unsigned int inputfreq);
extern unsigned int ChangFreq8BitTo16Bit(unsigned char inputfreq);
extern void RDSMute(unsigned char type);
extern void RDSSetFreq(unsigned char setfreq);
extern void RDSAFSearchSetFreq(unsigned char setfreq);
extern void RDSFastEnable(void);
extern void RDSFastDisable(void);
extern void CalSendBuff(void);

typedef struct RDS_stuct {
	unsigned char SyncBits;
	unsigned char SyncCnt;
	unsigned int BlockA;
	unsigned int BlockB;
	unsigned int BlockC;
	unsigned int BlockCp;
	unsigned int BlockD;
	unsigned int BlockLastA;
	unsigned int BlockLastB;
	unsigned int BlockLastC;
	unsigned int BlockLastCp;
	unsigned int BlockLastD;
	unsigned char Level;
	unsigned char MaxLevel;
	
	unsigned int PI;
	unsigned int PILast;
	unsigned int PILast2;
	unsigned int PIBackup;
	unsigned int PISeekBackup;
	unsigned int PISeekTimer;
	unsigned char PTY;
	unsigned char PTYLast;
	unsigned TP:1;
	unsigned TPLast:1;
	unsigned TA:1;
	unsigned TALast:1;
	unsigned EONTP:1;
	unsigned EONTPLast:1;
	unsigned EONTA:1;
	unsigned EONTALast:1;
	unsigned char Group;
	unsigned char PS[8];
	unsigned int PSCRC;
	unsigned int PSCRCTemp;
	unsigned char TimeHour;
	unsigned char TimeMin;
	
	unsigned long MJD;
	
	unsigned char AF[25];
	unsigned char AFFreqBackup;
	unsigned char AFNum;
	unsigned char AFTimer;
	unsigned char AFCheckMode;
	unsigned char AFCheckPoint;
	unsigned char AFCheckStartTimer;
	unsigned char AFCheckStartTimerSet;
	unsigned char AFCheckWaitTimer;
	unsigned char AFCheckWaitTimerSet;
	unsigned char AFSearchWaitTimer;
	unsigned char RDSStationDelayTimer;
	unsigned char AFSmeterLevel;
	unsigned char AFSmeterCheckFreqTimer;
	unsigned char AFSmeter[25];
	unsigned char AFDisable[25];
	unsigned char AFMethod[2];
	unsigned char AFDisableTimer;

	#ifdef EON_ENABLE
	unsigned char	EONAF[25];
	unsigned char	EONAFNum;
	unsigned char	EONAFTimer;
	unsigned int EONPI;
	unsigned char EONPS[8];
	
	unsigned char	EONAFBackup[25];
	unsigned char	EONAFNumBackup;
	unsigned char	EONAFTimerBackup;
	unsigned int EONPIBackup;
	unsigned char EONPSBackup[8];
	#endif

	#ifdef RT_ENABLE
	unsigned char RT[64];
	#endif
	
	unsigned F_GetOneGroup:1;
	unsigned F_GetBlockA:1;
	unsigned F_GetBlockB:1;
	unsigned F_GetBlockC:1;
	unsigned F_GetBlockCp:1;
	unsigned F_GetBlockD:1;
	unsigned F_BlockA:1;
	unsigned F_BlockB:1;
	unsigned F_BlockC:1;
	unsigned F_BlockCp:1;
	unsigned F_BlockD:1;
	unsigned F_RDSStation:1;
	unsigned F_AFMethodB:1;

	unsigned F_GetNewPI:1;
	unsigned F_GetNewPTY:1;
	unsigned F_GetNewTP:1;
	unsigned F_GetNewTA:1;
	unsigned F_GetNewEONTP:1;
	unsigned F_GetNewEONTA:1;
	unsigned F_PSGet0:1;
	unsigned F_PSGet1:1;
	unsigned F_PSGet2:1;
	unsigned F_PSGet3:1;
	unsigned F_PSExist:1;
	unsigned F_GetNewPS:1;
	unsigned F_GetNewCT:1;
	unsigned F_GetNewAF:1;
	unsigned F_GetAFList:1;
	unsigned F_GetEONAFList:1;
	unsigned F_GetNewRT:1;
	unsigned F_RTABFlag:1;

	unsigned F_GetNewEONAF:1;

	unsigned F_AFEnable:1;
	unsigned F_TAEnable:1;
	unsigned F_PTYEnable:1;
	unsigned F_REGEnable:1;
	unsigned F_EONEnable:1;
	unsigned F_PIMuteEnable:1;
	unsigned F_PISeek:1;
	unsigned F_RDSStationSlow:1;
	
} RDSStuct;

ext   RDSStuct RDS;

ext unsigned int RDSAFFreq[2];
ext unsigned char RDSAFBuff[2][3];

#define GROUP0			((RDS.Group>>1)==0)
#define GROUP0A			(RDS.Group==0x00)
#define GROUP0B			(RDS.Group==0x01)

#define GROUP2			((RDS.Group>>1)==2)
#define GROUP2A			(RDS.Group==0x04)
#define GROUP2B			(RDS.Group==0x05)

#define GROUP4			((RDS.Group>>1)==4)
#define GROUP4A			(RDS.Group==0x08)

#define GROUP14			((RDS.Group>>1)==14)
#define GROUP14A		(RDS.Group==0x1C)
#define GROUP14B		(RDS.Group==0x1D)

#define GROUP15B		(RDS.Group==0x1F)

//#define RDSStation	(RDS.PI!=0)//RDS.F_RDSStation
#define RDSStation		(RDS.MaxLevel>4)
#define NotRDSStation	(RDS.MaxLevel<5)

#define AFCHECK_MODE_IDLE			0
#define AFCHECK_MODE_REQ			1
#define AFCHECK_MODE_CHECK			2
#define AFCHECK_MODE_CHECKWAIT		3
#define AFCHECK_MODE_CHECKEND		4
#define AFCHECK_MODE_CHECKRDS		5
#define AFCHECK_MODE_CHECKPI		6
#define AFCHECK_MODE_SEARCHREQ		7
#define AFCHECK_MODE_SEARCHRDS		8
#define AFCHECK_MODE_SEARCHPI		9

//#define RDSAFChecking	(RDS.AFCheckMode!=AFCHECK_MODE_IDLE)
#define RDSAFChecking	(RDS.AFCheckMode!=AFCHECK_MODE_IDLE&&RDS.AFCheckStartTimerSet==10)//icon only flash when <20db 



ext unsigned char Delta;

ext unsigned char AFCheckDisable1sTimer;
ext unsigned char AFCheckBetweenList1sTimer;//AF Check Time period between complete AF list 
ext unsigned char AFCheckBetweenList100msTimer;
ext unsigned char AFCheckBetweenFreq10msTimer;//AF Check Time period between two frequency in AF list 
ext unsigned char AFFastCheckBetweenList1sTimer;//AF Check Time period between complete AF list 
ext unsigned char AFFastCheckBetweenFreq10msTimer;//AF Check Time period between two frequency in AF list 
ext unsigned int PISeek100msTimer;
#endif

//FST field strength
ext unsigned char DB3;
ext unsigned char DB4;
ext unsigned char DB10;
ext unsigned char DB20;
ext unsigned char DB30;
ext unsigned char DB40;
/*********************************************************
				File End
*********************************************************/

